/**
 * com.dingjian.basedata.org.service.impl.PositionServiceImpl.java
 */
package com.dingjian.basedata.org.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.dingjian.base.dao.BaseDao;
import com.dingjian.base.service.impl.BaseServiceImpl;
import com.dingjian.base.util.StringUtils;
import com.dingjian.basedata.org.dao.PositionDao;
import com.dingjian.basedata.org.model.Position;
import com.dingjian.basedata.org.service.PositionService;

/**
 * @author FengMy
 *
 * @since 2012-10-7
 */
@Component(value="positionService")
@Transactional
public class PositionServiceImpl extends BaseServiceImpl<Position> implements
		PositionService {
	@Autowired
	private PositionDao positionDao;
	
	
	@Override
	public List<Position> getByOrg(String org) {
		return positionDao.getByOrg(org);
	}

	@Override
	protected BaseDao getDao() {
		return positionDao;
	}

	@Override
	public void savePositions(List<Position> positions) {
		for(Position p : positions){
			if(StringUtils.isEmpty(p.getId())){
				super.addEntity(p);
			}else{
				Position old = positionDao.getEntityById(p.getId());
				old.setName(p.getName());
				old.setLeading(p.getLeading());
				old.setJob(p.getJob());
				super.updateEntity(old);
			}
		}
	}
}
